# @Time   : 2022-03-03 17:00:00
# @Author : Gavin Jiang
# @Owner  : YSRD (Insights Value)

import os

import yaml

from framework.the_path import ThePath
from framework.decorator.synchronized import synchronized


class Environment(object):

    @synchronized
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):
            cls._instance = super().__new__(cls)
        return cls._instance

    def __init__(self):
        self.env = os.getenv('ENVIRONMENT', 'prod')
        # with open(ThePath.config(['default', 'env.yml'])) as f:
        #     self._config = yaml.load(f,Loader=yaml.FullLoader)

    @staticmethod
    def is_prod() -> bool:
        return Environment().env == 'prod'

    @staticmethod
    def is_pre() -> bool:
        return Environment().env == 'pre'

    @staticmethod
    def is_dev() -> bool:
        return Environment().env == 'dev'

    @staticmethod
    def env() -> str:
        return Environment().env


# class Environment(object):
#
#     @synchronized
#     def __new__(cls, *args, **kwargs):
#         if not hasattr(cls, '_instance'):
#             cls._instance = super().__new__(cls)
#         return cls._instance
#
#     def __init__(self):
#         with open(ThePath.config(['default', 'env.yml'])) as f:
#             self._config = yaml.load(f,Loader=yaml.FullLoader)
#
#     @staticmethod
#     def is_prod() -> bool:
#         return Environment()._config.get('env') == 'prod'
#
#     @staticmethod
#     def is_pre() -> bool:
#         return Environment()._config.get('env') == 'pre'
#
#     @staticmethod
#     def is_dev() -> bool:
#         return Environment()._config.get('env') == 'dev'
#
#     @staticmethod
#     def env() -> str:
#         return Environment()._config.get('env')

# print(Environment.is_prod())